﻿#include "test.h"
#include "detail.h"

#ifdef _DEBUG

namespace ksini
{
 
	namespace test 
	{


		void  do_test_ini()
		{
			using namespace std;
			ksini::IniFile ini ;
			cout << ini << endl;

			cout<< "\n  add some values into section \n";

			ini.get_value("sect1", "mykey", "myval");
			ini.get_value("sect1", "mykey2", "myval2");
			ini.get_value("sect1", "mykey3", "myval3");
			ini.get_value("sect1", "mykey4", "myval4");
			ini.get_value("sect1", "mykey5", "myval5");

			// add mode values to other sections
			ini.set_value("sect2", "val0", "rewetr46346");
			ini.set_value("sect2", "val1", "hgfh");
			ini.set_value("sect2", "val2", "kjjgy");

			ini.set_value("sect2", "val2", "kjjgy");



			ini.set_bool("values", "mybol", false);
			bool bval = ini.get_bool("values", "mybol", true);

			ini.set_int("values", "myint", 555);
			int ival = ini.get_int("values", "myint", 777);

			ini.set_float("values", "myfloat", 1.111f);
			float fval = ini.get_float("values", "myfloat", 3.333f);





			cout << ini << endl;

			cout <<  "  \n\n write content to file ... \n";
			ini.save_to_file("myini.ini");

			// clear all data (clear all sections)
			ini.clear_all();

			// 
			cout << "\n load data from file \n";
			ini.load_from_file("myini.ini");

			cout << "\n after load: \n";
			cout << ini << endl;



			cout << "\n\n end\n";
			int _stop =0;
		}


		void  do_test_load()
		{
			using namespace std;
			cout << "\n\n----------------------------\n\n";
			ksini::IniFile ini;
			ini.load_from_file("myini.ini");
			cout << ini;



			int _end =0;
		}

		void  do_test_2()
		{
			using namespace std;

			ksini::IniFile ini;

			std::string path = detail::extractFilePath(__FILE__);
			path += "sample.ini";
			ini.load_from_file(path);
			cout << ini << endl;
		
		
			cout << "";

			path = detail::extractFilePath(__FILE__);
			path += "sample_after_save.ini";
			ini.save_to_file(path);

		}

		void do_test_ininode()
		{

			{
				IniNode node("mynode", "comment", NULL);
				node.apendChildKeyValue("key0", "value0", "comment0");

				std::string dest;

				int level = 4;
				node.apendToStr(dest, level);


				int _end =0;
			}

			{
				//
				IniTree tree;
				tree.root.apendChildKeyValue("dffdsfsdf", "vxccvxcv", "cxczxczx");
				tree.root.apendChildKeyValue("sdffdsfsdf", "vxccvxcv", "cxczxczx");
				tree.root.apendChildKeyValue("vxcnbvn", "vxccvxcv", "cxczxczx");
				tree.root.apendChildKeyValue("yr765", "vxccvxcv", "cxczxczx");

				IniNode& n = tree.root.apendChildNode("vcxvcvxc", "bvbvcbcvbcvb");
				n.apendChildKeyValue("dfdgfhgfhdff", "dfastrytydfasdfsdf", "000000000000000000");
				n.apendChildKeyValue("gfddfdgfhgfhdff", "dfayusdfasdfsdf", "rytreuytrut");
				n.apendChildKeyValue("bvmbdfdgfhgfhdff", "dfjghasdfasdfsdf", "rytreuytrut");
				n.apendChildKeyValue("fhgfhdff", "bcvxbdfasdfasdfsdf", "rytreuytrut");


				IniNode& n2 = tree.root.apendChildNode("mbnmbnmv", "gsdfgfgsg");
				n2.apendChildKeyValue("vbcxbcvbxc", "dfast897987rytydfasdfsdf", "mnmvbm");
				n2.apendChildKeyValue("tuyyh", "4355", "gfhf");
				n2.apendChildKeyValue("ewter785", "879689", "7567567");
				n2.apendChildKeyValue("bvcbncvn-687687", "567657457", "8908970890");




				tree.saveToFile("tree.ini");
				tree.root.clearKeyValues();
				tree.root.clearNodes();

				tree.loadFromFile("tree.ini");

				int _end =0;
			}



		//	assert(false);




		}


	}


}


#endif
